﻿using EkStudio.com.bean.xml.reflection;
using System;
using System.Collections.Generic;

namespace EkStudio.com.bean.xml.RootInterface.FieldEvent
{
    public class BillDataFillRoot :BillUiFormatContainer
    {
        private int maxid = 0;
        private List<BillDataFillItem> linkEvents;

        [Xml]
        public int Maxid
        {
            get
            {
                return maxid;
            }

            set
            {
                maxid = value;
            }
        }
        [XmlElement]
        public List<BillDataFillItem> LinkEvents
        {
            get
            {
                return linkEvents;
            }

            set
            {
                linkEvents = value;
            }
        }
        [XmlTransient]
        public object ParentBean
        {
            get
            {
                return null;
            }

            set
            {
               
            }
        }

        public object Clone()
        {
            BillDataFillRoot clone = new BillDataFillRoot();
            clone.Maxid = 0;
            clone.LinkEvents = new List<BillDataFillItem>();
            if (this.linkEvents != null && this.linkEvents.Count > 0)
            {
                for (int i = 0; i < linkEvents.Count; i++)
                {
                    Object it = linkEvents[i].Clone();
                    if (it is BillDataFillItem)
                    {
                        clone.LinkEvents.Add((BillDataFillItem)it);
                    }
                }
            }

            return clone;
        }

        #region 容器功能接口实现

        public void addNode(BillUiFormatNode node,BillFormatModule format)
        {
            node.LanguageTexts = this.getNLanguageText(format);
            if (this.linkEvents == null) this.linkEvents = new List<BillDataFillItem>();
            this.linkEvents.Add(node as BillDataFillItem);
        }

        public void removeNode(BillUiFormatNode node)
        {
            if (this.linkEvents != null&&this.linkEvents.Contains(node as BillDataFillItem))
            {
                this.linkEvents.Remove(node as BillDataFillItem);
            }
        }

        public void moveUp(BillUiFormatNode node)
        {
            
        }

        public void moveDown(BillUiFormatNode node)
        {
            
        }

        public string getNLanguageText(BillFormatModule format)
        {
            String result = "";
            String language = format.getLanguageText();
            if (language.Length > 0)
            {
                int index = language.IndexOf("Caption");
                if (index != -1)
                {
                    int len = language.Length - 7;
                    String first = language.Substring(0, len);
                    int max = this.maxid + 1;
                    this.maxid = max;
                    result = first + "Events[" + max + "].Caption";
                }
            }
            return result;
        }

        public void updateLanguageText(BillFormatModule format)
        {
            if (this.linkEvents != null && this.linkEvents.Count > 0)
            {
                foreach(BillDataFillItem it in this.linkEvents)
                {
                    it.LanguageTexts = this.getNLanguageText(format);
                }
            }
        }


        #endregion
    }
}
